//初始化树形菜单
function initZtree(treeData){
    var setting = {
        data:{
            key: {
                name: "menuName",
                children:"childMenu"
            }
        },
        callback: {
            onClick: zTreeOnClick
        }
    };
    zTreeObj= $.fn.zTree.init($("#ztreelist"), setting, treeData);
}
//节点单击加载当前节点所有的操作权限（已有的操作勾选上）
function zTreeOnClick(event, treeId, treeNode) {
   var buttonTable=  $('#data_table').DataTable({
        info : true, //显示表格左下角信息
        ordering: false,//关闭表格默认排序
        paging: true, //分页
        processing:true, //设置为true,就会有表格加载时的提示
        searching: false, //关闭本地搜索
        serverSide: true,//如果是服务器方式，必须要设置为true
        //使用ajax异步请求
        ajax:{
            dataSrc: function (json) {
                json.draw = json.data.draw;
                json.recordsTotal = json.data.recordsTotal;
                json.recordsFiltered = json.data.recordsFiltered;
                return json.data.data;
            },
            url:'/sysButton/getSysButtonListBySmId',
            type:'post',
            "data": {
                "smId": treeNode.smId
            }
        },
        columns: [
            { data: null,title: "<input type='checkbox' name='checklist' id='checkall' class='checkall'/>",
                render: function(data, type, row, meta) {return '<input id="checkchild" type="checkbox"  class="checkchild" value="' + row.sbId + '" />'}
            },
            {data:"index",title:"序号",
                render:function(data,type,row,meta){var startIndex = meta.settings._iDisplayStart;return startIndex+meta.row+1}
            },
            { data: 'sbId' ,title:"id"},
            { data: 'buttonName' ,title:"按钮名称"},
            { data: 'buttonMethod' ,title:"按钮方法"},
            { data: 'description' ,title:"描述"}
        ]
    });
    buttonTable.ajax.reload();
    // layer.msg(treeNode.smId + ", " + treeNode.menuName, {
    //     time: 20000, //20s后自动关闭
    //     btn: ['关闭']
    // });
//        layer.closeAll('page');
//        var names = treeNode.name.split('|');
}
//页面加载获取树形菜单数据
$(function () {
    $.post("/sysRole/getMenuTreeByRoleId",{roleId:$("#roleId").val()},function(result){
        if(result){
            if (result['status']===0){
                initZtree(result['data']);
            }else {
                layer.alert(result['msg']);
            }
        }else{
            layer.alert('系统异常');
        }
    });
});